
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Acquiring Source Code for PAs · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-page-footer-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-callouts/plugin.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="styles.css">
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="PA1.html" />
    
    
    <link rel="prev" href="0.6.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="./">
            
                <a href="./">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="PA0.html">
            
                <a href="PA0.html">
            
                    
                    PA0 - 世界诞生的前夜: 开发环境配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="0.1.html">
            
                <a href="0.1.html">
            
                    
                    Installing a GNU/Linux VM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="0.2.html">
            
                <a href="0.2.html">
            
                    
                    First Exploration with GNU/Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="0.3.html">
            
                <a href="0.3.html">
            
                    
                    Installing Tools
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="0.4.html">
            
                <a href="0.4.html">
            
                    
                    Configuring vim
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="0.5.html">
            
                <a href="0.5.html">
            
                    
                    More Exploration
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="0.6.html">
            
                <a href="0.6.html">
            
                    
                    Transferring Files between host and container
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.7" data-path="0.7.html">
            
                <a href="0.7.html">
            
                    
                    Acquiring Source Code for PAs
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="PA1.html">
            
                <a href="PA1.html">
            
                    
                    PA1 - 开天辟地的篇章: 最简单的计算机
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="1.1.html">
            
                <a href="1.1.html">
            
                    
                    在开始愉快的PA之旅之前
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="1.2.html">
            
                <a href="1.2.html">
            
                    
                    开天辟地的篇章
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="1.3.html">
            
                <a href="1.3.html">
            
                    
                    RTFSC
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="1.4.html">
            
                <a href="1.4.html">
            
                    
                    基础设施
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="1.5.html">
            
                <a href="1.5.html">
            
                    
                    表达式求值
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="1.6.html">
            
                <a href="1.6.html">
            
                    
                    监视点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="1.7.html">
            
                <a href="1.7.html">
            
                    
                    i386手册
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="PA2.html">
            
                <a href="PA2.html">
            
                    
                    PA2 - 简单复杂的机器: 冯诺依曼计算机系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="2.1.html">
            
                <a href="2.1.html">
            
                    
                    不停计算的机器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="2.2.html">
            
                <a href="2.2.html">
            
                    
                    RTFSC(2)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="2.3.html">
            
                <a href="2.3.html">
            
                    
                    程序, 运行时环境与AM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="2.4.html">
            
                <a href="2.4.html">
            
                    
                    基础设施(2)
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="2.5.html">
            
                <a href="2.5.html">
            
                    
                    输入输出
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="PA3.html">
            
                <a href="PA3.html">
            
                    
                    PA3 - 穿越时空的旅程: 批处理系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="3.1.html">
            
                <a href="3.1.html">
            
                    
                    最简单的操作系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="3.2.html">
            
                <a href="3.2.html">
            
                    
                    穿越时空的旅程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="3.3.html">
            
                <a href="3.3.html">
            
                    
                    用户程序和系统调用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="3.4.html">
            
                <a href="3.4.html">
            
                    
                    文件系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="3.5.html">
            
                <a href="3.5.html">
            
                    
                    批处理系统
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="PA4.html">
            
                <a href="PA4.html">
            
                    
                    PA4 - 虚实交错的魔法: 分时多任务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="4.1.html">
            
                <a href="4.1.html">
            
                    
                    多道程序
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="4.2.html">
            
                <a href="4.2.html">
            
                    
                    虚实交错的魔法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="4.3.html">
            
                <a href="4.3.html">
            
                    
                    超越容量的界限
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="4.4.html">
            
                <a href="4.4.html">
            
                    
                    来自外部的声音
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="4.5.html">
            
                <a href="4.5.html">
            
                    
                    编写不朽的传奇
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="PA5.html">
            
                <a href="PA5.html">
            
                    
                    PA5 - 天下武功唯快不破: 程序与性能
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="5.1.html">
            
                <a href="5.1.html">
            
                    
                    浮点数的支持
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="5.2.html">
            
                <a href="5.2.html">
            
                    
                    通往高速的次元
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="5.3.html">
            
                <a href="5.3.html">
            
                    
                    天下武功唯快不破
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="blank.html">
            
                <a href="blank.html">
            
                    
                    杂项
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="why.html">
            
                <a href="why.html">
            
                    
                    为什么要学习计算机系统基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="submit.html">
            
                <a href="submit.html">
            
                    
                    实验提交要求
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="linux.html">
            
                <a href="linux.html">
            
                    
                    Linux入门教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="man.html">
            
                <a href="man.html">
            
                    
                    man入门教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="git.html">
            
                <a href="git.html">
            
                    
                    git入门教程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="i386-intro.html">
            
                <a href="i386-intro.html">
            
                    
                    i386手册指令集阅读指南
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="exec.html">
            
                <a href="exec.html">
            
                    
                    指令执行例子
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="." >Acquiring Source Code for PAs</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h2 id="acquiring-source-code-for-pas">Acquiring Source Code for PAs</h2>
<h3 id="getting-source-code">Getting Source Code</h3>
<p>Go back to the home directory by</p>
<pre><code>cd ~
</code></pre><p>Usually, all works unrelated to system should be performed under the home directory.
Other directories under the root of file system (<code>/</code>) are related to system.
Therefore, do NOT finish your PAs and Labs under these directories by <code>sudo</code>.</p>
<div class="panel panel-danger"><div class="panel-heading"><h3 class="panel-title" id="&#x4E0D;&#x8981;&#x4F7F;&#x7528;root&#x8D26;&#x6237;&#x505A;&#x5B9E;&#x9A8C;"><i class="fa fa-exclamation"></i> &#x4E0D;&#x8981;&#x4F7F;&#x7528;root&#x8D26;&#x6237;&#x505A;&#x5B9E;&#x9A8C;!!!</h3></div><div class="panel-body"><p>&#x4F7F;&#x7528;root&#x8D26;&#x6237;&#x8FDB;&#x884C;&#x5B9E;&#x9A8C;, &#x4F1A;&#x6539;&#x53D8;&#x5B9E;&#x9A8C;&#x76F8;&#x5173;&#x6587;&#x4EF6;&#x7684;&#x6743;&#x9650;&#x5C5E;&#x6027;, &#x53EF;&#x80FD;&#x4F1A;&#x5BFC;&#x81F4;&#x5F00;&#x53D1;&#x8DDF;&#x8E2A;&#x7CFB;&#x7EDF;&#x65E0;&#x6CD5;&#x6B63;&#x5E38;&#x5DE5;&#x4F5C;;
&#x66F4;&#x4E25;&#x91CD;&#x7684;, &#x4F60;&#x7684;&#x8BEF;&#x64CD;&#x4F5C;&#x53EF;&#x80FD;&#x4F1A;&#x65E0;&#x610F;&#x4E2D;&#x635F;&#x574F;&#x7CFB;&#x7EDF;&#x6587;&#x4EF6;, &#x5BFC;&#x81F4;&#x865A;&#x62DF;&#x673A;/&#x5BB9;&#x5668;&#x65E0;&#x6CD5;&#x542F;&#x52A8;!
&#x5F80;&#x5C4A;&#x6709;&#x82E5;&#x5E72;&#x5B66;&#x957F;&#x56E0;&#x6B64;&#x800C;&#x5F71;&#x54CD;&#x4E86;&#x5B9E;&#x9A8C;&#x8FDB;&#x5EA6;, &#x751A;&#x81F3;&#x7531;&#x4E8E;&#x635F;&#x574F;&#x4E86;&#x5B9E;&#x9A8C;&#x76F8;&#x5173;&#x7684;&#x6587;&#x4EF6;&#x800C;&#x5F71;&#x54CD;&#x4E86;&#x5206;&#x6570;.
&#x8BF7;&#x5927;&#x5BB6;&#x5F15;&#x4EE5;&#x4E3A;&#x9274;, &#x4E0D;&#x8981;&#x8D2A;&#x56FE;&#x65B9;&#x4FBF;, &#x5426;&#x5219;&#x540E;&#x679C;&#x81EA;&#x8D1F;!</p><p>&#x5982;&#x679C;&#x4F60;&#x4ECD;&#x7136;&#x4E0D;&#x7406;&#x89E3;&#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x8FD9;&#x6837;&#x505A;, &#x4F60;&#x53EF;&#x4EE5;&#x9605;&#x8BFB;&#x8FD9;&#x4E2A;&#x9875;&#x9762;: <a href="http://askubuntu.com/questions/16178/why-is-it-bad-to-login-as-root" target="_blank">Why is it bad to login as root?</a>
&#x6B63;&#x786E;&#x7684;&#x505A;&#x6CD5;&#x662F;: &#x6C38;&#x8FDC;&#x4F7F;&#x7528;&#x4F60;&#x7684;&#x666E;&#x901A;&#x8D26;&#x53F7;&#x505A;&#x90A3;&#x4E9B;&#x5B89;&#x5206;&#x5B88;&#x5DF1;&#x7684;&#x4E8B;&#x60C5;(&#x4F8B;&#x5982;&#x5199;&#x4EE3;&#x7801;),
&#x5F53;&#x4F60;&#x9700;&#x8981;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x9700;&#x8981;root&#x6743;&#x9650;&#x624D;&#x80FD;&#x8FDB;&#x884C;&#x7684;&#x64CD;&#x4F5C;&#x65F6;, &#x4F7F;&#x7528;<code>sudo</code>.</p></div></div>
<p>Now acquire source code for PA by the following command:</p>
<pre><code>git clone -b 2018 https://github.com/NJU-ProjectN/ics-pa.git ics2018
</code></pre><p>A directory called <code>ics2018</code> will be created.
This is the project directory for PAs.
Details will be explained in PA1.</p>
<p>Issue the following commands to perform <code>git</code> configuration:</p>
<pre><code>git config --global user.name &quot;171220000-Zhang San&quot; # your student ID and name
git config --global user.email &quot;zhangsan@foo.com&quot;   # your email
git config --global core.editor vim                 # your favorite editor
git config --global color.ui true
</code></pre><p>You should configure <code>git</code> with your student ID, name, and email.
Before continuing, please read <a href="git.html">this</a> <code>git</code> tutorial to learn some basics of <code>git</code>.</p>
<p>Enter the project directory <code>ics2018</code>, then run</p>
<pre><code>git branch -m master
bash init.sh
</code></pre><p>to initialize all the subprojects.
This script will pull 4 subprojects from github.
We will explain them later.
Besides, the script will also add some environment variables into the bash configuration file <code>~/.bashrc</code>.
These variables are defined by absolute path to support the compilation of the subprojects.
Therefore, <font color="red">DO NOT move your project to another directory once the initialization finishes</font>,
else these variables will become invalid.
Particularly, if you use shell other than <code>bash</code>,
please set these variables in the corresponding configuration file manually.</p>
<h3 id="git-usage">Git usage</h3>
<p>We will use the <code>branch</code> feature of <code>git</code> to manage the process of development.
A branch is an ordered list of commits, where a commit refers to some modifications in the project.</p>
<p>You can list all branches by</p>
<pre><code>git branch
</code></pre><p>You will see there is only one branch called &quot;master&quot; now.</p>
<pre><code>* master
</code></pre><p>To create a new branch, use <code>git checkout</code> command:</p>
<pre><code>git checkout -b pa0
</code></pre><p>This command will create a branch called <code>pa0</code>, and check out to it.
Now list all branches again, and you will see we are now at branch <code>pa0</code>:</p>
<pre><code>  master
* pa0
</code></pre><p>From now on, all modifications of files in the project will be recorded in the branch <code>pa0</code>.</p>
<p>Now have a try!
Modify the <code>STUID</code> and <code>STUNAME</code> variables in <code>nemu/Makefile.git</code>:</p>
<pre><code>STUID = 171220000  # your student ID
STUNAME = &#x5F20;&#x4E09;     # your Chinese name
</code></pre><p>Run</p>
<pre><code>git status
</code></pre><p>to see those files modified from the last commit:</p>
<pre><code>On branch pa0
Changes not staged for commit:
  (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)
  (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)

    modified:   nemu/Makefile.git

no changes added to commit (use &quot;git add&quot; and/or &quot;git commit -a&quot;)
</code></pre><p>Run</p>
<pre><code>git diff
</code></pre><p>to list modifications from the last commit:</p>
<pre><code class="lang-diff">diff --git a/nemu/Makefile.git b/nemu/Makefile.git
index c9b1708..b7b2e02 100644
<span class="hljs-comment">--- a/nemu/Makefile.git</span>
<span class="hljs-comment">+++ b/nemu/Makefile.git</span>
<span class="hljs-meta">@@ -1,4 +1,4 @@</span>
<span class="hljs-deletion">-STUID = 171220000</span>
<span class="hljs-deletion">-STUNAME = &#x5F20;&#x4E09;</span>
<span class="hljs-addition">+STUID = 171221234</span>
<span class="hljs-addition">+STUNAME = &#x674E;&#x56DB;</span>

  # DO NOT modify the following code!!!
</code></pre>
<p>You should see <code>STUID</code> and <code>STUNAME</code> are modified.
Now add the changes to commit by <code>git add</code>, and issue <code>git commit</code>:</p>
<pre><code>git add .
git commit
</code></pre><p>The <code>git commit</code> command will call the text editor.
Type <code>modified my info</code> in the first line, and keep the remaining contents unchanged.
Save and exit the editor, and this finishes a commit.
Now you should see a log labeled with your student ID and name by</p>
<pre><code>git log
</code></pre><p>Now switch back to the <code>master</code> branch by</p>
<pre><code>git checkout master
</code></pre><p>Open <code>nemu/Makefile.git</code>, and you will find that <code>STUID</code> and <code>STUNAME</code> are still unchanged!
By issuing <code>git log</code>, you will find that the commit log you just created has disappeared!</p>
<p>Don&apos;t worry! This is a feature of branches in <code>git</code>.
Modifications in different branches are isolated,
which means modifying files in one branch will not affect other branches.
Switch back to <code>pa0</code> branch by</p>
<pre><code>git checkout pa0
</code></pre><p>You will find that everything comes back!
At the beginning of PA1, you will merge all changes in branch <code>pa0</code> into <code>master</code>.</p>
<p>The workflow above shows how you will use branch in PAs:</p>
<ul>
<li>before starting a new PA, new a branch <code>pa?</code> and check out to it</li>
<li>coding in the branch <code>pa?</code> (this will introduce lot of modifications)</li>
<li>after finish the PA, merge the branch <code>pa?</code> into <code>master</code>, and check out back to <code>master</code></li>
</ul>
<h3 id="compiling-and-running-nemu">Compiling and Running NEMU</h3>
<p>Now enter <code>nemu/</code> directory, and compile the project by <code>make</code>:</p>
<pre><code>make
</code></pre><p>If nothing goes wrong, NEMU will be compiled successfully.</p>
<div class="panel panel-danger"><div class="panel-heading"><h3 class="panel-title" id="&#x672A;&#x627E;&#x5230;xxx&#x547D;&#x4EE4;"><i class="fa fa-bullhorn"></i> &#x672A;&#x627E;&#x5230;xxx&#x547D;&#x4EE4;</h3></div><div class="panel-body"><p>&#x4F60;&#x6709;&#x53EF;&#x80FD;&#x4F1A;&#x9047;&#x5230;&#x8FD9;&#x4E2A;&#x9519;&#x8BEF;&#x4FE1;&#x606F;, &#x597D;&#x5427;&#x786E;&#x5B9E;&#x662F;&#x8BB2;&#x4E49;&#x758F;&#x5FFD;&#x4E86;.
&#x90A3;&#x5C31;&#x6B63;&#x597D;&#x5F53;&#x4F5C;&#x4E00;&#x4E2A;&#x7EC3;&#x4E60;&#x5427;: &#x4F60;&#x9700;&#x8981;&#x628A;&#x7F3A;&#x5C11;&#x7684;&#x5DE5;&#x5177;&#x88C5;&#x4E0A;.</p><p>&#x81F3;&#x4E8E;&#x600E;&#x4E48;&#x88C5;, &#x5F53;&#x7136;&#x662F;STFW&#x4E86;.</p></div></div>
<!-- -->
<div class="panel panel-info"><div class="panel-heading"><h3 class="panel-title" id="what-happened"><i class="fa fa-question-circle"></i> What happened?</h3></div><div class="panel-body"><p>You should know how a program is generated in the &#x7A0B;&#x5E8F;&#x8BBE;&#x8BA1;&#x57FA;&#x7840; course.
But do you have any idea about what happened when a bunch of information is output to the screen during <code>make</code> is executed?</p></div></div>
<p>To perform a fresh compilation, type</p>
<pre><code>make clean
</code></pre><p>to remove the old compilation result, then <code>make</code> again.</p>
<p>To run NEMU, type</p>
<pre><code>make run
</code></pre><p>However, you will see an error message:</p>
<pre><code>nemu: nemu/src/cpu/reg.c:21: reg_test: Assertion `(cpu.gpr[check_reg_index(i)]._16) == (sample[i] &amp; 0xffff)&apos; failed.
</code></pre><p>This message tells you that the program has triggered an assertion fail
at line 21 of the file <code>nemu/src/cpu/reg.c</code>.
If you do not know what is assertion, blame the &#x7A0B;&#x5E8F;&#x8BBE;&#x8BA1;&#x57FA;&#x7840; course.
If you go to see the line 21 of <code>nemu/src/cpu/reg.c</code>,
you will discover the failure is in a test function.
This failure is expected, because you have not implemented the register structure correctly.
Just ignore it now, and you will fix it in PA1.</p>
<p>To debug NEMU with gdb, type</p>
<pre><code>make gdb
</code></pre><h3 id="development-tracing">Development Tracing</h3>
<p>Once the compilation succeeds, the change of source code will be traced by <code>git</code>.
Type</p>
<pre><code>git log
</code></pre><p>If you see something like</p>
<pre><code>commit 4072d39e5b6c6b6837077f2d673cb0b5014e6ef9
Author: tracer-ics2018 &lt;tracer@njuics.org&gt;
Date:   Sun Jul 26 14:30:31 2018 +0800

    compile
    171220000
    user
    Linux debian 3.16.0-4-686-pae #1 SMP Debian 3.16.7-3 i686 GNU/Linux
     14:30:31 up  3:44,  2 users,  load average: 0.28, 0.09, 0.07
    3860572d5cc66412bf85332837c381c5c8c1009f
</code></pre><p>this means the change is traced successfully.</p>
<p>If you see the following message while executing make, this means the tracing fails.</p>
<pre><code>fatal: Unable to create &apos;/home/user/ics2018/.git/index.lock&apos;: File exists.

If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
</code></pre><p>Try to clean the compilation result and compile again:</p>
<pre><code>make clean
make
</code></pre><p>If the error message above always appears, please contact us as soon as possible.</p>
<div class="panel panel-danger"><div class="panel-heading"><h3 class="panel-title" id="&#x5F00;&#x53D1;&#x8DDF;&#x8E2A;"><i class="fa fa-exclamation"></i> &#x5F00;&#x53D1;&#x8DDF;&#x8E2A;</h3></div><div class="panel-body"><p>&#x6211;&#x4EEC;&#x4F7F;&#x7528;<code>git</code>&#x5BF9;&#x4F60;&#x7684;&#x5B9E;&#x9A8C;&#x8FC7;&#x7A0B;&#x8FDB;&#x884C;&#x8DDF;&#x8E2A;, &#x4E0D;&#x5408;&#x7406;&#x7684;&#x8DDF;&#x8E2A;&#x8BB0;&#x5F55;&#x4F1A;&#x5F71;&#x54CD;&#x4F60;&#x7684;&#x6210;&#x7EE9;.
&#x5F80;&#x5C4A;&#x6709;&#x5B66;&#x957F;&quot;&#x5B8C;&#x6210;&quot;&#x4E86;&#x67D0;&#x90E8;&#x5206;&#x5B9E;&#x9A8C;&#x5185;&#x5BB9;, &#x4F46;&#x6211;&#x4EEC;&#x627E;&#x4E0D;&#x5230;&#x76F8;&#x5E94;&#x7684;git log, &#x6700;&#x7EC8;&#x8BE5;&#x90E8;&#x5206;&#x5185;&#x5BB9;&#x88AB;&#x89C6;&#x4E3A;&#x6CA1;&#x6709;&#x5B8C;&#x6210;.
git log&#x662F;&#x72EC;&#x7ACB;&#x5B8C;&#x6210;&#x5B9E;&#x9A8C;&#x7684;&#x6700;&#x6709;&#x529B;&#x8BC1;&#x636E;, &#x5B8C;&#x6210;&#x4E86;&#x5B9E;&#x9A8C;&#x5185;&#x5BB9;&#x5374;&#x7F3A;&#x5C11;&#x5408;&#x7406;&#x7684;git log,
&#x4E0D;&#x4EC5;&#x4F1A;&#x635F;&#x5931;&#x5927;&#x91CF;&#x5206;&#x6570;, &#x8FD8;&#x4F1A;&#x7ED9;&#x6284;&#x88AD;&#x5224;&#x5B9A;&#x63D0;&#x4F9B;&#x6700;&#x6709;&#x529B;&#x7684;&#x8BC1;&#x636E;.
&#x56E0;&#x6B64;, &#x8BF7;&#x4F60;&#x6CE8;&#x610F;&#x4EE5;&#x4E0B;&#x4E8B;&#x9879;:</p><ul>
<li>&#x8BF7;&#x4F60;&#x4E0D;&#x5B9A;&#x671F;&#x67E5;&#x770B;&#x81EA;&#x5DF1;&#x7684;git log, &#x68C0;&#x67E5;&#x662F;&#x5426;&#x4E0E;&#x81EA;&#x5DF1;&#x7684;&#x5F00;&#x53D1;&#x8FC7;&#x7A0B;&#x76F8;&#x7B26;.</li>
<li>&#x63D0;&#x4EA4;&#x5F80;&#x5C4A;&#x4EE3;&#x7801;&#x5C06;&#x88AB;&#x89C6;&#x4E3A;&#x6CA1;&#x6709;&#x63D0;&#x4EA4;.</li>
<li>&#x4E0D;&#x8981;&#x628A;&#x4F60;&#x7684;&#x4EE3;&#x7801;&#x4E0A;&#x4F20;&#x5230;&#x516C;&#x5F00;&#x7684;&#x5730;&#x65B9;.</li>
<li>&#x603B;&#x662F;&#x5728;&#x5DE5;&#x7A0B;&#x76EE;&#x5F55;&#x4E0B;&#x8FDB;&#x884C;&#x5F00;&#x53D1;, &#x4E0D;&#x8981;&#x5728;&#x5176;&#x5B83;&#x5730;&#x65B9;&#x8FDB;&#x884C;&#x5F00;&#x53D1;, &#x7136;&#x540E;&#x4E00;&#x6B21;&#x6027;&#x5C06;&#x4EE3;&#x7801;&#x590D;&#x5236;&#x5230;&#x5DE5;&#x7A0B;&#x76EE;&#x5F55;&#x4E0B;, &#x8FD9;&#x6837;<code>git</code>&#x5C06;&#x4E0D;&#x80FD;&#x6B63;&#x786E;&#x8BB0;&#x5F55;&#x4F60;&#x7684;&#x5F00;&#x53D1;&#x8FC7;&#x7A0B;.</li>
<li>&#x4E0D;&#x8981;&#x4FEE;&#x6539;<code>Makefile</code>&#x4E2D;&#x4E0E;&#x5F00;&#x53D1;&#x8DDF;&#x8E2A;&#x76F8;&#x5173;&#x7684;&#x5185;&#x5BB9;.</li>
<li>&#x4E0D;&#x8981;&#x5220;&#x9664;&#x6211;&#x4EEC;&#x8981;&#x6C42;&#x521B;&#x5EFA;&#x7684;&#x5206;&#x652F;, &#x5426;&#x5219;&#x4F1A;&#x5F71;&#x54CD;&#x6211;&#x4EEC;&#x7684;&#x811A;&#x672C;&#x8FD0;&#x884C;, &#x4ECE;&#x800C;&#x5F71;&#x54CD;&#x4F60;&#x7684;&#x6210;&#x7EE9;</li>
<li>&#x4E0D;&#x8981;&#x6E05;&#x9664;git log</li>
</ul><p>&#x5076;&#x7136;&#x7684;&#x8DDF;&#x8E2A;&#x5931;&#x8D25;&#x4E0D;&#x4F1A;&#x5F71;&#x54CD;&#x4F60;&#x7684;&#x6210;&#x7EE9;.
&#x5982;&#x679C;&#x4E0A;&#x6587;&#x4E2D;&#x7684;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x603B;&#x662F;&#x51FA;&#x73B0;, &#x8BF7;&#x5C3D;&#x5FEB;&#x8054;&#x7CFB;&#x6211;&#x4EEC;.</p></div></div>
<h3 id="local-commit">Local Commit</h3>
<p>Although the development tracing system will trace the change of your code
after every successful compilation, the trace record is not suitable for your development.
This is because the code is still buggy at most of the time.
Also, it is not easy for you to identify those bug-free traces.
Therefore, you should trace your bug-free code manually.</p>
<p>When you want to commit the change, type</p>
<pre><code>git add .
git commit --allow-empty
</code></pre><p>The <code>--allow-empty</code> option is necessary,
because usually the change is already committed by development tracing system.
Without this option, <code>git</code> will reject no-change commits.
If the commit succeeds, you can see a log labeled with your student ID and name by</p>
<pre><code>git log
</code></pre><p>To filter out the commit logs corresponding to your manual commit, use <code>--author</code> option with <code>git log</code>.
For details about how to use this option, RTFM.</p>
<h3 id="submission">Submission</h3>
<p>Finally, you should submit your project to the submission website.
To submit PA0, put your report file (ONLY <code>.pdf</code> file is accepted) under the project directory.</p>
<pre><code>ics2018
&#x251C;&#x2500;&#x2500; 171220000.pdf   # put your report file here
&#x251C;&#x2500;&#x2500; init.sh
&#x251C;&#x2500;&#x2500; Makefile
&#x251C;&#x2500;&#x2500; nanos-lite
&#x251C;&#x2500;&#x2500; navy-apps
&#x251C;&#x2500;&#x2500; nemu
&#x251C;&#x2500;&#x2500; nexus-am
&#x2514;&#x2500;&#x2500; README.md
</code></pre><p>Double check whether everything is fine.
Then go back to the project directory, issue</p>
<pre><code>make submit
</code></pre><p>This command does 3 things:</p>
<ol>
<li>Cleanup unnecessary files for submission</li>
<li>Cleanup unnecessary files in git</li>
<li>Download a script from the server and run it to submit everything to the specific website</li>
</ol>
<p>The script will ask you to enter the task name.
Enter <code>PA0</code> for this submission.
If everything is fine, the script will output a <code>SUCCESS</code> message.</p>
<div class="panel panel-danger"><div class="panel-heading"><h3 class="panel-title" id="&#x53C8;&#x62A5;&#x9519;&#x4E86;"><i class="fa fa-bullhorn"></i> &#x53C8;&#x62A5;&#x9519;&#x4E86;</h3></div><div class="panel-body"><p>&#x6211;&#x77E5;&#x9053;, &#x90A3;&#x4F60;&#x8BF4;&#x8BE5;&#x600E;&#x4E48;&#x529E;&#x5462;?</p></div></div>
<h2 id="rtfsc-and-enjoy">RTFSC and Enjoy</h2>
<p>If you are new to GNU/Linux and finish this tutorial by yourself, congratulations! You have learn a lot!
The most important, you have learn STFW and RTFM for using new tools and trouble-shooting. <font color="red">(&#x53CD;&#x601D;&#x4E00;&#x4E0B;, &#x4F60;&#x771F;&#x7684;&#x505A;&#x5230;&#x4E86;&#x5417;?)</font>
With these skills, you can solve lots of troubles by yourself during PAs, as well as in the future.</p>
<p>In PA1, the first thing you will do is to <a href="http://i.linuxtoy.org/docs/guide/ch48s06.html" target="_blank">RTFSC</a>.
If you have troubles during reading the source code, go to RTFM:</p>
<ul>
<li>If you can not find the definition of a function, it is probably a library function.
Read <code>man</code> for more information about that function.</li>
<li>If you can not understand the code related to hardware details, refer to the i386 manual.</li>
</ul>
<p>By the way, you will use C language for programming in all PAs.
<a href="http://docs.huihoo.com/c/linux-c-programming" target="_blank">Here</a> is an excellent tutorial about C language.
It contains not only C language (such as how to use <code>printf()</code> and <code>scanf()</code>),
but also other elements in a computer system
(data structure, computer architecture, assembly language, linking, operating system, network...).
It covers most parts of this course.
You are strongly recommended to read this tutorial.</p>
<p>Finally, enjoy the journey of PAs,
and you will find hardware is not mysterious, so does the computer system!
But remember:</p>
<ul>
<li><font color="red">STFW</font></li>
<li><font color="red">RTFM</font></li>
<li><font color="red">RTFSC</font>

</li>
</ul>
<div class="panel panel-success"><div class="panel-heading"><h3 class="panel-title" id="reminder"><i class="fa fa-flag"></i> Reminder</h3></div><div class="panel-body"><p>This ends PA0. And there is no &#x5FC5;&#x7B54;&#x9898; in PA0.</p></div></div>
<footer class="page-footer-ex"> <span class="page-footer-ex-copyright"> By <a href="https://sashimi-yzh.github.io/" target="_blank">Zihao Yu</a>, &#x91C7;&#x7528;<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" target="_blank">&#x77E5;&#x8BC6;&#x5171;&#x4EAB; &#x7F72;&#x540D;-&#x975E;&#x5546;&#x4E1A;&#x6027;&#x4F7F;&#x7528;-&#x76F8;&#x540C;&#x65B9;&#x5F0F;&#x5171;&#x4EAB; 3.0 &#x4E2D;&#x56FD;&#x5927;&#x9646; &#x8BB8;&#x53EF;&#x534F;&#x8BAE;</a>&#x53D1;&#x5E03; </span> &#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0; <span class="page-footer-ex-footer-update"> &#x6B64;&#x9875;&#x9762;&#x4FEE;&#x8BA2;&#x4E8E;:  2019-05-03 18:16:13 </span> </footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="0.6.html" class="navigation navigation-prev " aria-label="Previous page: Transferring Files between host and container">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="PA1.html" class="navigation navigation-next " aria-label="Next page: PA1 - 开天辟地的篇章: 最简单的计算机">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Acquiring Source Code for PAs","level":"1.2.7","depth":2,"next":{"title":"PA1 - 开天辟地的篇章: 最简单的计算机","level":"1.3","depth":1,"path":"PA1.md","ref":"PA1.md","articles":[{"title":"在开始愉快的PA之旅之前","level":"1.3.1","depth":2,"path":"1.1.md","ref":"1.1.md","articles":[]},{"title":"开天辟地的篇章","level":"1.3.2","depth":2,"path":"1.2.md","ref":"1.2.md","articles":[]},{"title":"RTFSC","level":"1.3.3","depth":2,"path":"1.3.md","ref":"1.3.md","articles":[]},{"title":"基础设施","level":"1.3.4","depth":2,"path":"1.4.md","ref":"1.4.md","articles":[]},{"title":"表达式求值","level":"1.3.5","depth":2,"path":"1.5.md","ref":"1.5.md","articles":[]},{"title":"监视点","level":"1.3.6","depth":2,"path":"1.6.md","ref":"1.6.md","articles":[]},{"title":"i386手册","level":"1.3.7","depth":2,"path":"1.7.md","ref":"1.7.md","articles":[]}]},"previous":{"title":"Transferring Files between host and container","level":"1.2.6","depth":2,"path":"0.6.md","ref":"0.6.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"3.x.x","theme":"default","variables":{},"plugins":["localized-footer","page-footer-ex","callouts"],"pluginsConfig":{"callouts":{"flag":{"alert":"success","picto":"fa-flag"},"question":{"alert":"info","picto":"fa-question-circle"},"info":{"alert":"info","picto":"fa-info-circle"},"todo":{"alert":"warning","picto":"fa-edit"},"caution":{"alert":"danger","picto":"fa-bullhorn"},"danger":{"alert":"danger","picto":"fa-exclamation"},"showTypeInHeader":false},"page-footer-ex":{"copyright":"By [Zihao Yu](https://sashimi-yzh.github.io/), 采用[知识共享 署名-非商业性使用-相同方式共享 3.0 中国大陆 许可协议](http://creativecommons.org/licenses/by-nc-sa/3.0/cn/)发布","markdown":true,"update_format":"YYYY-MM-DD HH:mm:ss","update_label":"此页面修订于: "},"search":{},"localized-footer":{"filename":"FOOTER.md","hline":"true"},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles.css","pdf":"styles.css"}},"file":{"path":"0.7.md","mtime":"2019-05-03T10:16:13.720Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-03T10:26:23.925Z"},"basePath":".","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="gitbook/gitbook.js"></script>
    <script src="gitbook/theme.js"></script>
    
        
        <script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

